package com.xcity.game.item.drop.impl;

import com.xcity.db.entity.Player;
import com.xcity.game.common.GameStaticConfig;
import com.xcity.game.item.drop.RangeDrop;
import com.xcity.game.item.drop.listener.DropListener;
import com.xcity.game.item.drop.listener.ExpDropListener;

import naga.x.util.CommonUtils;

public class ExpDrop extends RangeDrop {

	public ExpDrop(int exp) {
		this(GameStaticConfig.defaultChanceBase, 0, exp);
	}
	
	public ExpDrop(int probability, int weight, int exp) {
		this(probability, weight, exp, exp);
	}
	
	public ExpDrop(int probability, int weight, int minExp, int maxExp) {
		this.probability = probability;
		this.weight = weight;
		this.min = minExp;
		this.max = maxExp;
	}

	@Override
	protected void processDrop(Player player, String cause, DropListener listener) {
		int exp = CommonUtils.randomInt(RND, min, max);
		if (exp <= 0) {
			return;
		}
		if (player != null) {
			player.addExp(exp, cause);
		}
		if (listener != null && listener instanceof ExpDropListener) {
			((ExpDropListener) listener).expDroped(player, exp);
		}
	}

	public int getExp() {
		return max;
	}

}
